#ifndef MSG_STREAM
#define MSG_STREAM

#include <fstream>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include "configure.hpp"

using namespace std;

// file io stream
class msgstream {
    public:
    enum Mode
    {
        READ,
        WRITE
    };
    private:
    char fileName[max_filename];
    int onePieceSize;
    Mode mode;

    ifstream ifs;

    fstream ofs;

    public:

    unsigned long fileSize;

    // init a msgsteam
    msgstream(Mode _mode,const char* out_name,int _onePieceSize=msg_onePieceSize);

    // move a valiable piece from input file to output file 
    // with the io pointer move together.
    // copy the data to buffer
    // return the real size of copy data  
    size_t writePiece(char* buffer,int Write_size);
    size_t readPiece(char* buffer);

    size_t setPosition(unsigned long position);

    void close();
};

#endif